﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BUS;
using DTO;

namespace MasterPageGroupF3
{
    public partial class MuaHang : System.Web.UI.Page
    {
        
         
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.IsPostBack == false)
            {

                int idProduct = int.Parse(Request.QueryString["idProduct"].ToString());
                PRODUCT pro1 = PRODUCTBUS.LaySanPhamCoID(idProduct);
                idProduct = int.Parse(Request.QueryString["idProduct"].ToString());
                DropDownList1.Items.Insert(0, new ListItem("1"));
                DropDownList1.Items.Insert(1, new ListItem("2"));
                TextBox1.Text = pro1.PRICE.ToString();
                TextBox2.Text = pro1.PRICE.ToString();
            }
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {             
            if (Session["UserName"] == null)
            {
                Response.Write("<script language='javascript'>alert('Bạn chưa Đăng Nhập');</script>");
            }
            else
            {
                string username = Session["UserName"].ToString();                                         
                MEMBER Member = MEMBERBUS.getMemberByEmail(username);
                int idProduct = int.Parse(Request.QueryString["idProduct"].ToString());
                DateTime d = DateTime.Now;
                ORDER or = new ORDER();
                or.IDMEMBER = Member.IDMEMBER;                
                or.IDPRODUCT = idProduct;
                or.TIME = d;
                or.PRICE = int.Parse(TextBox1.Text);
                or.QUANTITY = int.Parse(DropDownList1.Text);
                or.STATUS = 0;
                ORDERBUS.AddOrder(or);
                Response.Write("<script language='javascript'>alert('Mua Hàng Thành công');</script>");
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idProduct = int.Parse(Request.QueryString["idProduct"].ToString());
            PRODUCT pro = PRODUCTBUS.LaySanPhamCoID(idProduct);
            int value = int.Parse(DropDownList1.Text);                         
            int thanhtien = value * (int)pro.PRICE;
            TextBox1.Text = thanhtien.ToString();

        }
    }
}